/**
 * Copyright © 2014 Winit Corp. All rights reserved.
 * This software is proprietary to and embodies the confidential
 * technology of Winit Corp.  Possession, use, or copying
 * of this software and media is authorized only pursuant to a
 * valid written license from Winit Corp or an authorized sublicensor.
 */
package com.winit.openapi.erp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.erp.spi.warehouse.WarehouseService;
import com.winit.erp.spi.warehouse.command.WarehouseCommand;
import com.winit.erp.spi.warehouse.vo.Warehouse;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

/**
 * TODO weifeng.liu: Change to the actual description of this class
 * 
 * @version Revision History
 * 
 * <pre>
 * Author     Version       Date        Changes
 * weifeng.liu    1.0           2015年3月18日     Created
 * 
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/erp/warehouse")
public class WarehouseController extends BaseController {

    @Autowired
    private WarehouseService warehouseService;

    @RequestMapping(value = "/queryWarehouse")
    public String queryWarehouse(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();

        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            WarehouseCommand command = new WarehouseCommand();
            // command.setWarehouseId(json.getLong("warehouseId"));
            command.setWarehouseType(json.getString("warehouseType"));
            List<Warehouse> list = warehouseService.getWarehouseList(command);
            responseMsg.setData(list);
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        return SUCCESS;
    }
}
